var express = require('express');
var router = express.Router();
var mongo = require('mongodb');
const db =require('../database/db.js');

const questionControl = require('../bin/control/questionControl')


router.get("/questionAdd",(req,res)=>{ //文章增加页
  res.render('questionAdd');
})

router.get('/questionList', function(req, res, next) { // 所有的问题
  var page = parseInt(req.query.page);
  if(!page){
    page = 1;
  }
  questionControl.count(function(number){
    questionControl.find_num(page,function(dbs){
    res.render('questionList',{data:JSON.stringify(dbs),data_h:dbs,number:number,page:page});
  });
 })
});

router.get('/questionEditor', function(req, res, next) { // 查看单一用户
  let _id = req.query.id;
  questionControl.findOneQuestion(_id,(result)=>{
    res.render('questionEditor',{userData:result,_id:_id});
  })
});



module.exports = router;
